package 数组;

import java.util.Scanner;

public class Main_209 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int s = scanner.nextInt();
        int[] ints = new int[6];
        for (int i = 0; i < ints.length; i++) {
            ints[i] = scanner.nextInt();
        }
        minSubArrayLen(s, ints);
        for (int i = 0; i < ints.length; i++) {
            System.out.println(ints[i]);
        }
    }

    public static int minSubArrayLen(int s, int[] nums) {
        int sum = 0;
        int strLength = 0;
        int i = 0;
        int result = Integer.MAX_VALUE;
        for (int j = 0; j < nums.length; j++) {
            sum = sum + nums[j];
            while (sum >= s) {
                strLength = j - i + 1;
                result = result < strLength ? result : strLength;
                sum = sum - nums[i++];
            }
        }
        return result == Integer.MAX_VALUE ? 0 : result;
    }
}
